<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LoginController extends Controller
{
    //渲染登录页
    public function index()
    {
        return view('login/login');
    }
    //用户登录
    public function login()
    {
        //验证
        $this->validate(request(),[
            'name'=>'required',
            'password'=>'required',
        ]);
        //逻辑
        $user = request(['name','password']);
        if(\Auth::attempt($user)){
            return redirect('/posts');
        }
        //渲染
        return \Redirect::back();
    }
    //退出
    public function logout()
    {
        \Auth::logout();
        return redirect('/login');
    }

}
